package com.cqggrw.service.impl;

import java.util.List;

import com.cqggrw.dao.UserDaoI;
import com.cqggrw.dao.impl.UserDaoImpl;
import com.cqggrw.domain.User;
import com.cqggrw.service.UserServiceI;
import com.cqggrw.util.Encrypt;

public class UserServiceImpl implements UserServiceI {

	private UserDaoI dao = new UserDaoImpl();
	
	public boolean add(User user) {
		user.setPwd(Encrypt.e(user.getPwd()));
		return dao.add(user);
	}

	public boolean del(Integer id) {
		return dao.del(id);
	}

	public boolean modify(User user) {
		user.setPwd(Encrypt.e(user.getPwd()));
		return dao.modify(user);
	}

	public User getById(User user) {
		return dao.getById(user);
	}

	public User login(User user) {
		User u = dao.getByName(user);
		if(u != null) {
			if(u.getPwd().equals(Encrypt.e(user.getPwd()))) {
				return u;
			}
		}
		return null;
	}

	public List<User> get() {
		return dao.get();
	}

}
